<?php
$tourCategory = $this->tourCategory;
$paginator    = $this->paginator;

$f = $this->form;

?>
<div class="wrapper-content">
    <div class="top-title">
        <div class="content-title">
            <h2><?php echo $this->translate('Share_This_To_Your_Friends');?>
            </h2>
        </div>
    </div>
    <div id="content-right-2">
        <?php echo $this->flashMessenger()?>
        <?php if($this->error != ''): ?>
            <div class="shout-box">
                <div class="alert alert-block 0">
                    <a class="close fade in" data-dismiss="alert" href="##">×</a>
                    <p style="font-weight:bold;text-align:center"><?php echo $this->translate($this->error); ?></p>
                </div>
            </div>
        <?php endif; ?>

        <div style="width:100%;float:left;">
    		<form onsubmit="" id="send-to-friend-form" name="inquyry_form" method="post" action="">
    			<table style="margin:20px 0px 0px 20px;width:700px;float:left;" cellspacing="4" cellpadding="4">
    				<tbody>
    					<tr>
    						<td class="">
    							<span><?php echo $this->translate('Full_name'); ?>&nbsp;</span><span class="required">*</span>
    						</td>
    						<td>
    						    <?php echo $f->getElement('full_name'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class="">
    							<span><?php echo $this->translate('Email_address'); ?>&nbsp;</span><span class="required">*</span>
    						</td>
    						<td class="">
    							<?php echo $f->getElement('email'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class="">
    							<span><?php echo $this->translate('Reconfirm_email_address'); ?>&nbsp;</span><span class="required">*</span>
    						</td>
    						<td class="">
    							<?php echo $f->getElement('reconfirm_email'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class="">
    							<span><?php echo $this->translate('Send_to_email'); ?>&nbsp;</span><span class="required">*</span>
    						</td>
    						<td class="">
    							<?php echo $f->getElement('to_email'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class=""><span><?php echo $this->translate('Subject'); ?>&nbsp;</span><span class="required">*</span></td>
    						<td class="">
    							<?php echo $f->getElement('subject'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class=""><span><?php echo $this->translate('Message') ?>&nbsp;</span><span class="required">*</span></td>
    						<td class="">
    							<?php echo $f->getElement('message'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class=""><span><?php echo $this->translate('Captcha'); ?>&nbsp;</span><span class="required">*</span></td>
    						<td class="">
    							<?php echo $f->getElement('captcha'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class="">&nbsp;</td>
    						<td class="">
    							<input type="submit" value="<?php echo $this->translate('Send_Email'); ?>" id="submit" class="btn">
    							<input type="reset" value="<?php echo $this->translate('Reset'); ?>" id="reset" class="btn">
    						</td>
    					</tr>
    					<tr>
    						<td class="" colspan="2">
    							<span><?php echo $this->translate('Fields_marked_with_asterisk_'). ' <span class="required">*</span> '. $this->translate('_are_mandatory'); ?></span>
    						</td>
    					</tr>
    				</tbody>
    			</table>
    		</form>
		</div>
    </div><!-- end column left -->
    <!-- column right -->
    <div class="span4" id="content-left-2">
        <div class="clear" style="width: 100%; height: 10px;"></div>
            <?php //echo $this->partial('/right-render/support.phtml'); ?>
        <div class="clear" style="width: 100%; height: 20px;"></div>
    </div>
</div>


<script>
$(document).ready(function(){
	var form    = $("#send-to-friend-form");
	var name    = $("#full_name");
	var email   = $("#email");
	var reEmail = $("#reconfirm_email");
	var toEmail  = $("#to_email");
	var subject = $("#subject");
	var message = $("#message");

	name.blur(validateName);
	email.blur(validateEmail);
	reEmail.blur(validateReConfirmEmail);
	toEmail.blur(validateToEmail);
	subject.blur(validateSubject);
	message.blur(validateMessage);

	form.submit(function(){
		if(validateName() && validateEmail() && validateReConfirmEmail() && validateToEmail() && validateSubject() && validateMessage())
			return true;
		else
			return false;
	});
	function validateName(){
		if(name.val().length < 4){
			$(".full-name-error").remove();
			name.after("<ul class='errors full-name-error'><li><?php echo $this->translate("We_want_names_with_more_than_3_letters!"); ?></li></ul>");
			return false;
		}
		else{
			$(".full-name-error").remove();
			return true;
		}
	}

	function validateEmail(){
		var a = $("#email").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		if(filter.test(a)){
			$(".email-error").remove();
			return true;
		} else{
			$(".email-error").remove();
			email.after("<ul class='errors email-error'><li><?php echo $this->translate("Type_a_valid_email_please") ?></li></ul>");
			return false;
		}
	}
	function validateReConfirmEmail(){
		if( email.val() != reEmail.val() ){
			$(".re-email-error").remove();
			reEmail.after("<ul class='errors re-email-error'><li><?php echo $this->translate("Reconfirm_email_doesn't_match!") ?></li></ul>");
			return false;
		}
		else{
			$(".re-email-error").remove();
			return true;
		}
	}
	function validateToEmail(){
		var list = $.trim($("#to_email").val()).split('\n');
	    var count = list.length;
	    var j = f = 0;
	    for(var i = 0; i <= count; i++) {
		    var a = $.trim(list[i]);
		    if(a != '' && a != null) {
        		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
        		if(filter.test(a)){
            		j = j + 1;
        		} else {
            		f = f + 1;
        			$(".to-email-error").remove();
        			toEmail.after("<ul class='errors to-email-error'><li><?php echo $this->translate("Type_valid_email_please") ?></li></ul>");
        			return false;
        		}
			}
		}
		if(j > 10) {
			$(".to-email-error").remove();
			toEmail.after("<ul class='errors to-email-error'><li><?php echo $this->translate('Please_enter_less_10_email_address') ?></li></ul>");
			return false;
		}
	    if(f === 0) {
	    	$(".to-email-error").remove();
	        return true;
		}
	}
	function validateSubject(){
		if(subject.val().length < 10){
			$(".subject-error").remove();
			subject.after("<ul class='errors subject-error'><li><?php echo $this->translate("We_want_subject_with_more_than_10_letters!") ?></li></ul>");
			return false;
		}
		else{
			$(".subject-error").remove();
			return true;
		}
	}
	function validateMessage(){
		if(message.val().length == 0){
			$(".message-error").remove();
			message.after("<ul class='errors message-error'><li><?php echo $this->translate("Value_is_required_and_can't_be_empty!") ?></li></ul>");
			return false;
		}
		else{
			$(".message-error").remove();
			return true;
		}
	}
});


$('.close').click(function() {
	$('.shout-box').remove();
});

</script>